home *** CD-ROM | disk | FTP | other *** search
- /*
- Grayscale Bitmap.c
-
- This file contains the calls to create a bitmap shape from scratch. It will create a 1 pixel high by 256 pixel gxWide grayscale bitmap.
- We will then scale the bitmap shape by 60 in the y direction.
-
- NOTE:
- • This file requires the following files to run correctly:
- "graphics shell.c", "GraphicsDebugLibrary.c", "TransformLibrary.c".
-
- • For the best printing results, print this file in "landscape".
-
-
- Change History:
-
- 4/96 bob Updated #includes to support changed GX Library names.
- Updated the note regarding the files needed to run.
- Updated the copyright date.
-
- ©1992 - 1996 Apple Computer, Inc.
- All rights reserved.
- */
-
- #include <events.h>
- #include <windows.h>
-
- #include <GXErrors.h>
- #include "GraphicsLibraries.h"
- #include <GXEnvironment.h>
- #include "graphics shell.h"
-
- //
- // Set up the title and size of the window
- //
- Str255 gWindowTitle = "\p Grayscale Bitmap ";
- Rect gWindowQDRect = {50, 20, 170, 345};
-
- //
- // gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
- // in main () within graphics shell.c. You can determine the amount of graphics gxHeap required by using GraphicsBug.
- // With gGraphicsHeapSize set to 60k, I had 7 free blocks left in the graphics gxHeap. Sounds good to me.
- //
- long gGraphicsHeapSize = 60;
-
-
- gxShape gBitShape;
-
-
- /*------ DoInitialization ---------------------------------------------------------------------------------*/
-
- void DoInitialization(gWindow)
- WindowPtr gWindow;
- {
- char bitImage[256];
- gxBitmap theBitmapData;
- gxPoint theBitmapPosition;
- short loop;
- gxColor grayPixelColor;
-
- gxViewPort windowViewPortParent;
-
- //
- // Get the gxViewPort that is attached to the window, and set the dither of this gxViewPort to 4. Which
- // will mean that all objects that are drawn into window will be dithered at a dither level of 4.
- //
- windowViewPortParent = GXGetWindowViewPort(gWindow);
- GXSetViewPortDither(windowViewPortParent, 4);
-
- //
- // Define gBitShape's starting position
- //
- theBitmapPosition.x = theBitmapPosition.y = ff(25);
-
- //
- // Define the gBitShape's structure. It will be a bitmap shape which is 1 pixel high and 256 pixels wide.
- // We will attach a gray color space below.
- //
- theBitmapData.image = bitImage;
- theBitmapData.width = 256;
- theBitmapData.height = 1;
- theBitmapData.rowBytes = 256;
- theBitmapData.pixelSize = 8;
- theBitmapData.space = gxNoSpace;
- theBitmapData.set = nil;
- theBitmapData.profile = nil;
-
- grayPixelColor.space = gxGraySpace;
- grayPixelColor.profile = nil;
-
- gBitShape = GXNewBitmap (&theBitmapData, &theBitmapPosition);
- GXSetShapeAttributes (gBitShape, gxMemoryShape);
-
- //
- // Create a gray pixel gxColor and change the value of the pixel within our bitmap shape. Starting with the first
- // pixel within our bitmap shape and moving to the right.
- //
- for (loop = 0; loop <= 255; ++loop) {
- grayPixelColor.element.gray = (loop << 8);
- GXSetShapePixel (gBitShape , loop, 0, &grayPixelColor, 0);
- }
-
- //
- // Scale our bitmap shape - gBitShape by 60 in the y direction. This will grow the height of the shape by 40.
- //
- GXScaleShape (gBitShape, fixed1, ff(60), theBitmapPosition.x, theBitmapPosition.y);
- }
-
-
- /*------ DoDraw ---------------------------------------------------------------------------------------*/
-
- void DoDraw(gWindow)
- WindowPtr gWindow;
- {
- GXDrawShape (gBitShape);
- }
-
-
- /*------ DoDispose -------------------------------------------------------------------------------------*/
-
- void DoDispose(gWindow)
- WindowPtr gWindow;
- {
- /**
- You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good
- form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
- call to DisposeWindow should dispose of the objects. If you are running the debugging version of the
- SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
- can turn notices on in this file by setting gDebugging = TRUE (above).
- **/
- GXDisposeShape(gBitShape);
- GXDisposeShape(gWindowBoundsShape);
- DisposeWindow(gWindow);
- }
-
-
- /*------ DoIdle ----------------------------------------------------------------------------------------*/
-
- void DoIdle(gWindow)
- WindowPtr gWindow;
- {
- }
-
-
- /*------ DoClick ---------------------------------------------------------------------------------------*/
-
- void DoClick( orgMouseLoc, theWindow )
- gxPoint orgMouseLoc;
- WindowPtr theWindow;
- {
- }
-
-
-
-